package com.exam.admin.controller;

import com.exam.admin.service.AdminService;
import com.exam.anno.MyLog;
import com.exam.entity.Admin;
import com.exam.entity.ApiResult;
import com.exam.entity.dto.LogTableDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

@RestController
public class AdminController {

    @Autowired
    private AdminService adminService;
    

    /**
     * 分页查询日志
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/selectMyLog/{page}/{size}")
    public ApiResult findAllLog(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        return adminService.findAllLog(page, size);
    }

    /**
     * 根据id 回显日志信息
     * @param logId
     * @return
     */
    @GetMapping("/updateMyLog")
    public ApiResult findByIdLog(@RequestParam("logId") Integer logId) {
        return adminService.findByIdLog(logId);
    }

    /**
     * 修改日志信息
     * @param logTableDto
     * @return
     */
    @PutMapping("/putMyLog")
    public ApiResult updateMyLog(@RequestBody LogTableDto logTableDto) {
        return adminService.updateMyLog(logTableDto);
    }

    /**
     * 根据id删除日志信息
     * @param logId
     * @return
     */
    @DeleteMapping("/admin/{logId}")
    public ApiResult deleteByIdMyLog(@PathVariable("logId") Integer logId) {
        return adminService.deleteByIdMyLog(logId);
    }

    /**
     * 根据id来查找管理员信息
     * @param adminId
     * @return
     */
    @GetMapping("/adminById/{adminId}")
    public ApiResult adminById(@PathVariable("adminId") Long adminId) {
        return adminService.adminById(adminId);
    }

    /**
     * 导出日志数据表
     * @param response
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response){
        adminService.exportBusinessData(response);
    }

    /**
     * 修改管理员信息
     * @param admin
     * @return
     */
    @PutMapping("/admin")
    public ApiResult updateByIdAdmin(@RequestBody Admin admin){
        return adminService.updateByIdAdmin(admin);
    }


}
